#coding:utf-8
from django.db import models
from django.core.urlresolvers import reverse
from DjangoUeditor.models import UEditorField
# Create your models here.
class EntryQuerySet(models.QuerySet):
    def published(self):
        return self.filter(publish=True)
#标签  
class Tag(models.Model):
    name = models.CharField(max_length=50,unique=True)
    description = models.CharField(max_length=100,null = True)
    
    class Meta:
        verbose_name = u'博客标签'
        verbose_name_plural = u'标签'
    
    def __unicode__(self):
        return '%s' % self.name
    
    @models.permalink
    def get_absolute_url(self):
        return ('tag',(),{
                'tag':self.name,})
    
#分类
class Category(models.Model):
    name = models.CharField(max_length=20,unique=True)
    description = models.CharField(max_length=60,null = True)
    sort = models.IntegerField(max_length=11,default=1)
    class Meta:
        verbose_name = u'博客类别'
        verbose_name_plural = u'分类'
    
    def __unicode__(self):
        return '%s' % self.name
    @models.permalink
    def get_absolute_url(self):
        return ('category',(),{
                'category':self.name,})
        
def getImagePath():
    return "temp/"   
#创建 Article 对象
class Article(models.Model):
    title = models.CharField(max_length=100) #博客的标题
#     category = models.CharField(max_length=50,blank = True) #博客的标签
    date_time = models.DateTimeField(auto_now_add = True) #博客的日期
    update_time = models.DateTimeField(auto_now=True) #博客更新时间
#     content = models.TextField(blank = True,null = True) #博客的正文
    image_url = models.URLField(u'配图',blank=True)
#     content = MarkdownField(blank = True,null = True)
    content = UEditorField('内容    ',height=400,width=686,toolbars='besttome',upload_settings={"imageMaxSize":1204000},)
    deleted = models.IntegerField(default=0)                     #是否已删除,默认0表未删除,1表示删除
    read_count = models.IntegerField(default=0) #阅读量
    categories = models.ManyToManyField('Category') #博客的标签
    tags = models.ManyToManyField('Tag')
    
    
    
    def get_absolute_url(self):
        path = reverse('detail',kwargs={'id':self.id})
        return "/blog_2/%s"% path
    
    def __unicode__(self):
        return '%s' % self.title
    
    class Meta: # 按时间下降排序
        verbose_name = u'文章'
        verbose_name_plural = u'博客正文'
        ordering = ['-date_time']

#网站基本信息
class BaseInformation(models.Model):
    title = models.CharField(max_length=100,help_text=u'浏览器顶部显示的内容')
    keywords = models.CharField(max_length=100,help_text=u'提供给搜索引擎的内容。关键词之间用英文逗号分隔')
    description = models.CharField(max_length=100,help_text=u'网站描述')
    icon_url = models.URLField(u'图标地址')
    logo_url = models.URLField(u'logo地址')
    blog_name = models.CharField(max_length=50,help_text=u'博客名称')
    mark = models.CharField(u'签名',max_length=100)
    content = models.TextField(u'自我介绍')
    copyrightby = models.CharField(u'版权声明',max_length=100)
    my_template = models.CharField(u'当前所用的主题',max_length=100)
    
    class Meta:
        verbose_name = u'网站基本设置'
        verbose_name_plural = u'网站基本设置'
    def __unicode__(self):
        return '%s' % self.title
    
class FriendlyLink(models.Model):
    title = models.CharField(max_length=50)
    url = models.URLField(u'网站地址')
    
    class Meta:
        verbose_name =u'友情链接'
        verbose_name_plural = u'友情链接'
        


        
import logging
from django.conf import settings
from django.db.models.signals import pre_save



